package cn.wolfcode.trip.app.controller;

import cn.wolfcode.trip.base.query.StrategyQueryObject;
import cn.wolfcode.trip.base.query.TravelQueryObject;
import cn.wolfcode.trip.base.service.IStrategyService;
import cn.wolfcode.trip.base.service.ITravelService;
import cn.wolfcode.trip.base.util.JsonResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/search")
public class SearchController {
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService   travelService;
    @GetMapping("/searchByKeyWord")
    public Object selectResult(@RequestParam String keyword){
        JsonResult jsonResult = new JsonResult();
        TravelQueryObject qo1 = new TravelQueryObject();
        StrategyQueryObject qo2 = new StrategyQueryObject();
        qo1.setKeyword(keyword);
        qo2.setKeyword(keyword);
        try {
            PageInfo<?> query = strategyService.selectListByKeyword(qo2);
            PageInfo<?> pageInfo = travelService.queryForSearchList(qo1);
            //如果两个都没有数据,返回异常
            if(query.getList().size() == 0 && pageInfo.getList().size() ==0){
                jsonResult.mark("服务器异常");
                return jsonResult;
            }
            return jsonResult;
        } catch (Exception e) {
            e.printStackTrace();
            jsonResult.mark("服务器异常");
            return jsonResult;
        }
    }

}
